package com.sunnada.btfvilg.controller;

import com.sunnada.btfvilg.common.response.Result;
import com.sunnada.btfvilg.common.response.ResultFactory;
import com.sunnada.btfvilg.entity.Deliverylist;
import com.sunnada.btfvilg.entity.Package;
import com.sunnada.btfvilg.model.request.PackageParamVo;
import com.sunnada.btfvilg.model.response.PackageItemVo;
import com.sunnada.btfvilg.model.response.PackageListVo;
import com.sunnada.btfvilg.model.response.PackageVo;
import com.sunnada.btfvilg.model.response.UserVo;
import com.sunnada.btfvilg.service.PackageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zsl
 * @title PackageController
 * @description: TODO
 */

@RestController
@RequestMapping("package")
@Api(tags = "快递包裹管理")
public class PackageController {
    @Autowired
    PackageService packageService;

    @PostMapping("/addPackage")
    @ApiOperation(value = "添加包裹", httpMethod = "POST")
    public Result<PackageVo> insertPackage(@Validated @RequestBody PackageParamVo pVo){
        PackageVo packageVo=packageService.addPackage(pVo);
        return ResultFactory.success("添加成功",packageVo);
    }

    @GetMapping("/deletePackage")
    @ApiOperation(value = "删除指定包裹", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pid", value = "包裹id", dataType = "String", paramType = "query", required = true)
    })
    public Result<Object> deletePackageById( String pid){
        packageService.delPackage(pid);
        return ResultFactory.success("删除成功", null);
    }

    @PostMapping("/updatePackage")
    @ApiOperation(value = "更新指定包裹信息", httpMethod = "POST")
    public Result<Object> updatePackage(@Validated @RequestBody PackageParamVo pVo){
        packageService.updatePackage(pVo);
        return ResultFactory.success("修改成功",null);
    }

    @GetMapping("/packageState")
    @ApiOperation(value = "更新包裹状态", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pid", value = "包裹id", dataType = "String", paramType = "query", required = true),
            @ApiImplicitParam(name = "pstate", value = "包裹状态", dataType = "String", paramType = "query", required = true)
    })
    public Result<Object> Package(String pid ,String pstate){
        packageService.Packagestate(pid,pstate);
        return ResultFactory.success(pstate+"成功",null);
    }

    @GetMapping("/getPackageList")
    @ApiOperation(value = "获取所有包裹信息", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页", dataType = "String", paramType = "query", required = true),
            @ApiImplicitParam(name = "numPerPage", value = "每页记录数", dataType = "String", paramType = "query", required = true)
    })
    public Result<PackageListVo> getAllPackage(Integer page, Integer numPerPage){
        PackageListVo packageList=packageService.getPackageList(page,numPerPage);
        return ResultFactory.success(packageList);
    }
    @GetMapping("/getPackageListByUid")
    @ApiOperation(value = "获取指定用户的包裹信息", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "uid", value = "用户id", dataType = "String", paramType = "query", required = true),
            @ApiImplicitParam(name = "page", value = "当前页", dataType = "String", paramType = "query", required = true),
            @ApiImplicitParam(name = "numPerPage", value = "每页记录数", dataType = "String", paramType = "query", required = true)
    })
    public Result<PackageListVo> getPackageListByUid(String uid, Integer page, Integer numPerPage){
        PackageListVo packageList=packageService.getPackageListByUid(uid,page,numPerPage);
        return ResultFactory.success(packageList);
    }

    @GetMapping("/getPackageListBySid")
    @ApiOperation(value = "获取指定网点的包裹信息", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sid", value = "网点id", dataType = "String", paramType = "query", required = true),
            @ApiImplicitParam(name = "page", value = "当前页", dataType = "String", paramType = "query", required = true),
            @ApiImplicitParam(name = "numPerPage", value = "每页记录数", dataType = "String", paramType = "query", required = true)
    })
    public Result<PackageListVo> getPackageListBySid(String sid, Integer page, Integer numPerPage){
        PackageListVo packageList=packageService.getPackageListBySid(sid,page,numPerPage);
        return ResultFactory.success(packageList);
    }

    @GetMapping("/getPackageListByDid")
    @ApiOperation(value = "获取指定快递员的包裹信息", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "did", value = "快递员id", dataType = "String", paramType = "query", required = true),
            @ApiImplicitParam(name = "page", value = "当前页", dataType = "String", paramType = "query", required = true),
            @ApiImplicitParam(name = "numPerPage", value = "每页记录数", dataType = "String", paramType = "query", required = true)
    })
    public Result<PackageListVo> getPackageListByDid(String did,Integer page, Integer numPerPage){
        PackageListVo packageList=packageService.getPackageListByDid(did,page,numPerPage);
        return ResultFactory.success(packageList);
    }

    @GetMapping("/getPackageByPid")
    @ApiOperation(value = "包裹订单查询", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pid", value = "包裹id", dataType = "String", paramType = "query", required = true),
    })
    public Result<PackageItemVo> getPackageListByPid(String pid){
        PackageItemVo packageitem=packageService.getPackageByPid(pid);
        return ResultFactory.success(packageitem);
    }

}
